package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class LoanCollection here.
 * 
 * @author (Allan Lie) 
 * @version (V1)
 */
public class LoanCollection
{
    private ArrayList<Loan> loans;
    
    
    private static LoanCollection loanCollection = new LoanCollection();
    
    private LoanCollection()
    {
        loans = new ArrayList<Loan>();
    }
    
    public static LoanCollection getInstance()
    {
        return loanCollection;
    }
    public ArrayList<Loan> getAllLoans()
    {
        return loans;
    }
    
    public void makeLoan(Loan loan)
    {
        loans.add(loan);
    }
    
    public Loan findLoan(int id)
    {
        int i = 0;
        boolean found = false;
        Loan loan = null;
        while(i < loans.size() && !found)
        {
            if(loans.get(i).getId() == id)
            {
                found = true;
                loan = loans.get(i);
            }
        i++;
        }
        return loan;
    }
    
    public boolean removeLoan(int id)
    {
        int i = 0;
        boolean found = false;
        Loan loan = null;
        while(i < loans.size() && !found)
        {
            if(loans.get(i).getId() == id)
            {
                found = true;
                loan = loans.remove(i);
            }
        i++;
        }
        return found;
    }
    
    public int findBiggestId()
    {
        int big = 0;
        for(Loan l : loans)
        {
            if(l.getId() > big)
            {
                big = l.getId();
            }
        }
        return big;
    }

}
